package com.yuque.util;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class kuayu implements WebMvcConfigurer {
    public static final long MAX_AGE=60*60;
    @Autowired
    private CommonInteceptor commonInteceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(commonInteceptor).addPathPatterns("/**");
    }
   @Override
    public void addCorsMappings(CorsRegistry registry){
       registry.addMapping("/**").allowedOrigins("*").allowedMethods("*").maxAge(MAX_AGE).allowedHeaders("*");
   }
    // 解决访问硬盘上的某个文件夹中的内容
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/tupian/**").addResourceLocations("file:E:/upload/");
    }

}
